/*
 * HubSessionDAO.java
 *
 * Created on June 16, 2007, 7:48 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jhub.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import jhub.HubSession;

/**
 *
 * @author dbotelho
 */
public class HubSessionDAO extends AbstractDAO {
    
     private final PreparedStatement addHubSessionStatement;
     
    
    /** Creates a new instance of HubSessionDAO */
    public HubSessionDAO(Connection conn) throws SQLException {
        super(conn);
        this.addHubSessionStatement = conn.prepareStatement("INSERT INTO hub_session (id,start,\"end\") VALUES(?,?,?)");
        
    }
    
    public void startHubSession(HubSession hubSession) throws SQLException{
        hubSession.setSessionID(super.nextValue("hub_session_id_seq"));
        addHubSessionStatement.setInt(1,hubSession.getSessionID());
        addHubSessionStatement.setLong(2,hubSession.getStartDate().getTime());
        
        if(hubSession.getEnd()!=null)
            addHubSessionStatement.setLong(3,hubSession.getEnd().getTime());
        else
            addHubSessionStatement.setNull(3,java.sql.Types.NULL);
        System.out.println(addHubSessionStatement.toString());
        addHubSessionStatement.executeUpdate();
    }
    
}
